﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace JinYuan.ControlLib
{

    [DefaultEvent("ControlDoubleClick")]
    public partial class UCFengSu : UserControl
    {
        public UCFengSu()
        {
            InitializeComponent();

            //设置控件样式，去除缓冲
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.SetStyle(ControlStyles.Selectable, true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.Size = new System.Drawing.Size(232, 43);
        }


        //private int titleScale = 50;
        //[Browsable(true)]
        //[Category("自定义属性")]
        //[Description("设置或获取标题所占比例")]
        //public int TitleScale
        //{
        //    get { return titleScale; }
        //    set
        //    {
        //        titleScale = value;

        //        this.MainTableLayoutControl.ColumnStyles[0] = new ColumnStyle(SizeType.Percent, titleScale);
        //    }
        //}


        //private int valueScale = 30;
        //[Browsable(true)]
        //[Category("自定义属性")]
        //[Description("设置或获取数据所占比例")]
        //public int ValueScale
        //{
        //    get { return valueScale; }
        //    set
        //    {
        //        valueScale = value;

        //        this.MainTableLayoutControl.ColumnStyles[1] = new ColumnStyle(SizeType.Percent, valueScale);
        //    }
        //}

        private string titleName = "参数名称设置";
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("设置或获取参数名称")]
        public string TitleName
        {
            get { return titleName; }
            set
            {
                titleName = value;

                this.lbl_Title.Text = titleName;
            }
        }

        private Color ucFengSuBG = Color.FromArgb(255, 77, 59);
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("设置或获取风扇控件背景颜色")]
        public Color UcFengSuBG
        {
            get { return ucFengSuBG; }
            set
            {
                ucFengSuBG = value;
                this.ucbFengSu.BlowerColor = ucFengSuBG;
            }
        }

        private Color ucFengSuFan = Color.FromArgb(3, 169, 243);
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("设置或获取风扇叶子颜色")]
        public Color UcFengSuFan
        {
            get { return ucFengSuFan; }
            set
            {
                ucFengSuFan = value;
                this.ucbFengSu.FanColor = ucFengSuFan;
            }
        }


        private float currentValue = 0.0f;
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("设置或获取当前数值")]
        public float CurrentValue
        {
            get { return currentValue; }
            set
            {
                currentValue = value;

                this.lbl_Value.Text = currentValue.ToString();
                this.ucbFengSu.TurnSpeed = 100;
                if (value > 0.0f)
                {
                    this.ucbFengSu.TurnAround = TurnAround.Clockwise;
                    this.ucbFengSu.TurnSpeed = (int)value;
                }
                else
                {
                    this.ucbFengSu.TurnAround = TurnAround.None;
                }

            }
        }

        [Browsable(true)]
        [Category("自定义属性")]
        [Description("设置或获取绑定变量名称")]
        public string BindVarName { get; set; }



        [Browsable(true)]
        [Category("自定义事件")]
        [Description("控件双击事件")]
        public event EventHandler ControlDoubleClick;

        private void lbl_Value_DoubleClick(object sender, EventArgs e)
        {
            if (ControlDoubleClick != null)
            {
                ControlDoubleClick(this, e);
            }
        }
    }
}